<?php
/**
 * Created by PhpStorm.
 * Script Name: Auth.php
 * Create: 12/17/22 11:42 AM
 * Description:
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace plugin\wechat\app\tenant\service;
use app\common\constant\Platform;
use app\common\service\Tenant as TenantService;

class Auth extends \app\tenant\service\Auth
{

    /**
     * 获取菜单
     * Author: fudaoji<fdj@kuryun.cn>
     * @param null $admin
     * @return array|mixed|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getMenuList($admin = null){
        $menus = plugin_config('menu')['tenant'];
        if(count($apps = TenantService::getCompanyActiveApps($admin, [['name','<>', 'wechat']]))){
            $mp_menus = ["title" => "应用模块", "icon" => "fa fa-cubes", "child" => []];
            $mini_menus = ["title" => "应用模块", "icon" => "fa fa-cubes", "child" => []];
            $bot_menus = ["title" => "应用模块", "icon" => "fa fa-cubes", "child" => []];
            foreach ($apps as $app){
                $types = explode(',', $app['type']);
                $menu = [
                    "title" => $app['title'], "href" => $app['tenant_url'], "target" => $app['tenant_url_type'] == 1 ? '_self':'_blank'
                ];
                in_array(Platform::MP, $types) && $mp_menus['child'][] = $menu;
                in_array(Platform::MINI, $types) && $mini_menus['child'][] = $menu;
                in_array(Platform::WECHAT, $types) && $bot_menus['child'][] = $menu;
            }
            count($mp_menus['child']) && $menus[0]['child'][] = $mp_menus;
            count($mini_menus['child']) && $menus[1]['child'][] = $mini_menus;
            count($bot_menus['child']) && $menus[2]['child'][] = $bot_menus;
        }

        if(self::isSuperAdmin($admin)){
            return $menus;
        }
        return [];
    }

    /**
     * 获取员工在当前应用中的权限
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public static function getAuthList($tenant = null){
        //todo
        return [];
    }
}